﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Reflection;
//using Mbs.Reflection;
//using Mbs.ComponentModel.Container.Context;

//namespace Mbs.ComponentModel.Container.Injection
//{
//    public class ConstructorInspect : MethodBaseInspect<ConstructorInfo>
//    {
//        public override IInjectContext<ConstructorInfo> Execute(IInspectContext ctx)
//        {
//            if (ctx == null
//               || ctx.Kernel == null)
//                return null;

//            Kernel = ctx.Kernel;
//            Component = ctx.Component;
//            return DoExecute(ctx);
//        }

//        protected override IInjectContext<ConstructorInfo> DoExecute(IInspectContext ctx)
//        {
//            var methods = (from c in ctx.Component.Implementation.GetConstructors()
//                           let ps = c.GetParameters()
//                           where Array.TrueForAll<ParameterInfo>(ps,p=>Filter(p))
//                           orderby ps.Length descending
//                           select c);

//            var result = (from m in methods
//                          let attr = m.GetAttribute<InjectAttribute>(true)
//                          where attr != null
//                          select new KeyValuePair<ConstructorInfo,InjectAttribute>(m,attr)).ToArray();
//            if (result != null && result.Length > 0)
//                return new InjectContext<ConstructorInfo>(ctx.Kernel,ctx.Component,ctx.Instance,result);

//            var constructor = methods.FirstOrDefault();

//            if (constructor == null)
//                throw new ActivatorException("Could not find eligible constructor for " + Component.Implementation.FullName);


//            return new InjectContext<ConstructorInfo>(ctx.Kernel, ctx.Component, ctx.Instance, new KeyValuePair<ConstructorInfo, InjectAttribute>[] { new KeyValuePair<ConstructorInfo, InjectAttribute>(constructor, null) }); 
//        }
//    }
//}
